﻿using mozhi.smarterp.AuthorCenter.Enums;
using mozhi.smarterp.AuthorCenter.Users.Permissions;
using System;
using Volo.Abp.Account;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Threading;

namespace mozhi.smarterp.AuthorCenter;

public static class AuthorCenterDtoExtensions
{
    private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner();

    public static void Configure()
    {
        OneTimeRunner.Run(() =>
        {
            /* You can add extension properties to DTOs
             * defined in the depended modules.
             *
             * Example:
             *
             * ObjectExtensionManager.Instance
             *   .AddOrUpdateProperty<IdentityRoleDto, string>("Title");
             *
             * See the documentation for more:
             * https://docs.abp.io/en/abp/latest/Object-Extensions
             */
            ObjectExtensionManager.Instance.AddOrUpdateProperty<IdentityUserDto, UserType>(
                "UserType"
            )
            .AddOrUpdateProperty<IdentityUserDto, Guid?>(
                "DepartmentId"
            )
             .AddOrUpdateProperty<IdentityUserDto, string[]>(
                "RoleNames"
            );

            ObjectExtensionManager.Instance.AddOrUpdateProperty<IdentityUserCreateDto, int>(
               "UserType",
               property =>
               {
                   property.Attributes.Clear();
               }
               )
               .AddOrUpdateProperty<IdentityUserCreateDto, Guid?>(
                   "DepartmentId"
               ).
                AddOrUpdateProperty<IdentityUserCreateDto, UserDataPermissionCreateDto>(
                   "DataPermission"
               );

            ObjectExtensionManager.Instance.AddOrUpdateProperty<IdentityUserUpdateDto, int>(
              "UserType"
              )
              .AddOrUpdateProperty<IdentityUserUpdateDto, Guid?>(
                  "DepartmentId"
              ).
                AddOrUpdateProperty<IdentityUserUpdateDto, UserDataPermissionUpdateDto>(
                   "DataPermission"
               );

            ObjectExtensionManager.Instance.AddOrUpdateProperty<IdentityRoleDto, RoleType>(
                "RoleType"
            );

            ObjectExtensionManager.Instance.AddOrUpdateProperty<IdentityRoleCreateDto, int>(
                "RoleType"
            );

            ObjectExtensionManager.Instance.AddOrUpdateProperty<IdentityRoleUpdateDto, int>(
                "RoleType"
            );
        });
    }
}
